﻿// JScript source code
String.prototype.trim = function(){return this.replace(/(^\s*)|(\s*$)/g, "");};
String.prototype.replaceAll = function(s1,s2) {return this.replace(new RegExp(s1,"gm"),s2);}

var patternDate = /^(\d{4})-(\d{2})-(\d{2})$/;
Date.prototype.getShortDateStr=function(){
	var str=this.getFullYear().toString();
	str+="-";
	if(this.getMonth()<9)
		str+="0";
	str+=(this.getMonth()+1).toString();
	str+="-";
	if(this.getDate()<10)
		str+="0";
	str+=this.getDate().toString();
	return str;
}
function DateDiff(sDate1, sDate2)
{
	var aDate, oDate1, oDate2, iDays 
	aDate = sDate1.split("-") 
	oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0])
	aDate = sDate2.split("-") 
	oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]) 
	iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 /24)
	return iDays 
}

function isIE(){ //ie? 
   if (window.navigator.userAgent.toLowerCase().indexOf("msie")>=1) 
    return true; 
   else 
    return false; 
} 

if(!isIE()){ //firefox innerText define
   HTMLElement.prototype.__defineGetter__(     "innerText", 
    function(){
     var anyString = "";
     var childS = this.childNodes;
     for(var i=0; i<childS.length; i++) {
      if(childS[i].nodeType==1)
       anyString += childS[i].tagName=="BR" ? '\n' : childS[i].innerText;
      else if(childS[i].nodeType==3)
       anyString += childS[i].nodeValue;
     }
     return anyString;
    } 
   ); 
   HTMLElement.prototype.__defineSetter__(     "innerText", 
    function(sText){ 
     this.textContent=sText; 
    } 
   ); 
}

function $Tag(){
  var elements = new Array();
  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementsByTagName(element);
    if (arguments.length == 1)
      return element;
    elements.push(element);
  }
  return elements;
}

function settopleft(obj, movobj,t,l){
    t=(t==undefined)?0:t;
    l=(l==undefined)?0:l;
    var leftpos=0;
	var toppos=0;
    aTag = obj;
	do {
		if( aTag.offsetParent )
		{
		    aTag = aTag.offsetParent;
		}
		else
		{
		    leftpos += aTag.style.left;
		    toppos += aTag.style.top;
		    break;
		}
		leftpos	+= aTag.offsetLeft;
		toppos += aTag.offsetTop;
	}while(aTag.name!="body");
	if(document.layers){
		movobj.style.left = obj.offsetLeft	+ parseInt(leftpos) + l + "px";
		movobj.style.top = obj.offsetTop +	parseInt(toppos) + obj.offsetHeight + t + "px";
	}else{
		movobj.style.left =obj.offsetLeft	+ parseInt(leftpos) + l  +"px";
		movobj.style.top = obj.offsetTop +	parseInt(toppos) + obj.offsetHeight + t  + "px";
	}
}
function gTL(obj,t){
    var leftpos=0;
	var toppos=0;
    aTag = obj;
	do {
		if( aTag.offsetParent )
		{
		    aTag = aTag.offsetParent;
		}
		else
		{
		    leftpos += aTag.style.left;
		    toppos += aTag.style.top;
		    break;
		}
		leftpos	+= aTag.offsetLeft;
		toppos += aTag.offsetTop;
	}while(aTag.name!="body");
	
	return (t=="top")?obj.offsetTop +	parseInt(toppos) + obj.offsetHeight:obj.offsetLeft	+ parseInt(leftpos);
	
}


///v:数组 setobj:赋值对象 sourceobj:目标 showobj:显示
function Helpbox(sourceobj,setobj, showobj, v){
	sourceobj.innerHTML="";
	var op, oText;
	for (var i=0;i<v[0].length;i++){
		op=document.createElement("div");
		op.setAttribute("title",v[0][i]);
		op.setAttribute("values",v[1][i]);
		op.onclick=function(){
			showobj.value=this.getAttribute("title");
			setobj.value=this.getAttribute("values");
		};
		op.onmouseover=function(){
			this.style.background="#F2F8FD";
			this.style.border="1px #9DCBF0 solid";
			this.style.borderLeftColor="#FFFFFF";
			this.style.borderRightColor="#FFFFFF";
			this.style.cursor="pointer";
		};
		op.onmouseout=function(){
			this.style.background="#FFFFFF";
			this.style.border="1px #FFFFFF solid";
			this.style.cursor="default";
		};
		oText=document.createTextNode(v[0][i]);
		op.appendChild(oText);
		sourceobj.appendChild(op);
	}
}

function Helpbox2(sourceobj,setobj, showobj, v){
	sourceobj.innerHTML="";
	var op, oText,objText;
	for (var i=0;i<v.length;i++){
		op=document.createElement("div");
		op.setAttribute("i", v.length);
		op.setAttribute("ii", setobj.length);
		op.setAttribute("title",v[i][0][0]);
		for(var ii=0;ii<setobj.length;ii++){
			op.setAttribute("setobj"+ii, setobj[ii]);
			op.setAttribute("showobj"+ii, showobj[ii]);
			if(v[i][ii]!=null){op.setAttribute("titlevalues"+ii, v[i][ii][0]);}else{op.setAttribute("titlevalues"+ii, "");}
			if(v[i][ii]!=null){op.setAttribute("values"+ii, v[i][ii][1]);}else{op.setAttribute("values"+ii, "");}
		}
		op.onclick=function(){
			var opii=parseInt(this.getAttribute("ii"));
			for(var iiii=0;iiii<opii;iiii++){
				if(this.getAttribute('setobj'+iiii)!=null){
					$(this.getAttribute('setobj'+iiii)).value=this.getAttribute('values'+iiii);
					$(this.getAttribute('showobj'+iiii)).value=this.getAttribute('titlevalues'+iiii);
				}
			}
		};
		op.onmouseover=function(){
			this.style.background="#F2F8FD";
			this.style.border="1px #9DCBF0 solid";
			this.style.borderLeftColor="#FFFFFF";
			this.style.borderRightColor="#FFFFFF";
			this.style.cursor="pointer";
		};
		op.onmouseout=function(){
			this.style.background="#FFFFFF";
			this.style.border="1px #FFFFFF solid";
			this.style.cursor="default";
		};
		var oText = v[i][0][0];
		if(v[i][1]!=null){oText+="<span style='font-size:9px;color:#666666'>("+v[i][1][0]+")</span>";}
		objText=document.createElement("span");
		objText.innerHTML = oText;
		op.appendChild(objText);
		sourceobj.appendChild(op);
	}
	
}

//信息框
function ShowMessageBox(obj,content,BoxWidth) 
{ 
	event.cancelBubble=true;
	$('MessageBox').innerHTML="<div style='text-align:left'>"+content+"<\/div>"; 
	settopleft(obj,$("MessageBox"),-1,0);
	$('MessageBox').style.display='block';
	messagesfromobj=obj;
	obj.onblur=function(){hidemessagesinfoplan($("MessageBox"))};
}
function HideMessageBox() { document.onclick=function(){$('MessageBox').style.display='none';document.onclick=function(){}; }; }
document.writeln("<div id=\"MessageBox\" name=\"MessageBox\"><\/div>");
$('MessageBox').style.border="none";
$('MessageBox').style.background="#B6B6B6";
var messagesfromobj = null;

function showmessagesinfoplan(obj, content, w){
	event.cancelBubble=true;
	if(typeof(document.getElementsByTagName("messagesinfoplan"))==undefined){
		document.write("<div id=\"messagesinfoplan\"><\/div>");
	}
	settopleft(obj,$("messagesinfoplan"),0,0);
	$("messagesinfoplan").style.width=w==""?"auto":w+"px";
	$("messagesinfoplan").innerHTML =content;
	$("messagesinfoplan").style.display="block";
	obj.onblur=function(){hidemessagesinfoplan($("messagesinfoplan"))};
	$("messagesinfoplan").onclick=function(){hidemessagesinfoplan($("messagesinfoplan"))};
	//document.onclick=function(){hidemessagesinfoplan($("messagesinfoplan"))}
}
function hidemessagesinfoplan(obj){ 
obj.style.display='none' 
} 



_PColl=new Object();
//中文：至少2个字，不能包含数字、字母、符号
//英文：名和姓中间用/分割，不能包含数字和其他字符
//中文人名验证规则
_PColl.ChineseNamePattern="^[\u4e00-\u9fa5]{2,20}$";
//检验字符串是否是中文
_PColl.ChinesePattern="^[\u4e00-\u9fa5]+$";
//中文生僻字,例如:王she
_PColl.rareChineseName1="^[\u4e00-\u9fa5]+[A-z]{2,}$";
//中文生僻字,例如:she王
_PColl.rareChineseName2="^[A-z]{2,}[\u4e00-\u9fa5]+$";
//中文生僻字,例如:shewang
_PColl.rareChineseName3="^[A-z]{3,}$";
//英文名
_PColl.EnglishName="^[a-z,A-Z ]{2,}\/[a-z,A-Z ]{2,}$";


function ValidValue(pstr,str)
{
	var patrn=new RegExp(pstr);
	return patrn.test(str);
}

var c_validator={
	isEmpty:function(v){
		return v.length==0?false:true;
	},
	isIllegalChar:function(v){//判断是否存在非法字符
		re=new RegExp("[\"\'\<\>\@\#\$\%\^\*\+\=]"); 
		if(re.test(v)){
			return true;
		}
		else{
			return false;
		}
	},
	isEmail:function(v){//判断EMAIL
		RegTest=new RegExp("^(([0-9a-zA-Z]+)|([0-9a-zA-Z]+[_.0-9a-zA-Z-]*[0-9a-zA-Z_]+))@([a-zA-Z0-9-]+[.])+([a-zA-Z]{2,4})$"); 
    	return RegTest.test(mail);
	},
	isValidZipCode:function(v){///*验证是否有效的邮政编码*/
		var reg = new RegExp('^[0-9]{6}$');
		if (v.search(reg) == -1)
			return false;
		return true;
	},	
	isValidEmail:function(s){/*验证是由有效的电子邮件地址*/
		var reg1 = new RegExp('^[a-zA-Z0-9][a-zA-Z0-9@._-]{3,}[a-zA-Z]$');
		var reg2 = new RegExp('[@.]{2}');
		if (s.search(reg1) == -1
				|| s.indexOf('@') == -1
				|| s.lastIndexOf('.') < s.lastIndexOf('@')
				|| s.lastIndexOf('@') != s.indexOf('@')
				|| s.search(reg2) != -1)
			return false;
			
		return true;
	},
	isValidMobile:function(v){/*验证是否有效的移动电话号码*/	
		RegTest = new RegExp("^18[0-9]|^13[0-9]|^17[0-9]|^19[0-9]|^14[0-9]|^15[0-9][0-9]{8}$");
		
		if (v.length != 11 && v.length != 12 )
		{	
			return false;
		}
		
		if (v.length == 12)
		{
			if (v.substr(0,1) == 0)
			{	
				v = v.substr(1,11);
			}
			else
			{	
				return false;
			}
		}
		return RegTest.test(v);		
	},
	
	isValidChinaIDCard:function(sNo){/*验证是否有效的中国身份证号码*/
		sNo = sNo.toString();
		if (sNo.length==18)
		{
			var a,b,c;
			if (!c_validator.isInteger(sNo.substr(0,17)))
			{
				return false;
			}
			a=parseInt(sNo.substr(0,1))*7+parseInt(sNo.substr(1,1))*9+parseInt(sNo.substr(2,1))*10;
			a=a+parseInt(sNo.substr(3,1))*5+parseInt(sNo.substr(4,1))*8+parseInt(sNo.substr(5,1))*4;
			a=a+parseInt(sNo.substr(6,1))*2+parseInt(sNo.substr(7,1))*1+parseInt(sNo.substr(8,1))*6;	
			a=a+parseInt(sNo.substr(9,1))*3+parseInt(sNo.substr(10,1))*7+parseInt(sNo.substr(11,1))*9;	
			a=a+parseInt(sNo.substr(12,1))*10+parseInt(sNo.substr(13,1))*5+parseInt(sNo.substr(14,1))*8;	
			a=a+parseInt(sNo.substr(15,1))*4+parseInt(sNo.substr(16,1))*2;
			b=a%11;
			
			if (b==2)
			{
				c=sNo.substr(17,1).toUpperCase();
			}
			else
			{
				c=parseInt(sNo.substr(17,1));
			}
			
			switch(b)
			{
				case 0: if ( c!=1 ) {return false;}break;
				case 1: if ( c!=0 ) {return false;}break;
				case 2: if ( c!="X") {return false;}break;
				case 3: if ( c!=9 ) {return false;}break;
				case 4: if ( c!=8 ) {return false;}break;
				case 5: if ( c!=7 ) {return false;}break;
				case 6: if ( c!=6 ) {return false;}break;
				case 7: if ( c!=5 ) {return false;}break;
				case 8: if ( c!=4 ) {return false;}break;
				case 9: if ( c!=3 ) {return false;}break;
				case 10: if ( c!=2 ){return false};
			}
		}
		else
		{
			if(sNo.length==15){
				if (isValidDate(sNo.substr(6,2),sNo.substr(8,2),sNo.substr(10,2))) {return true;}
				else{return false;}
			}
			else
			{
				return false;
			}
		}
		switch(sNo.length){
			case 15: if (isValidDate(sNo.substr(6,2),sNo.substr(8,2),sNo.substr(10,2))) {return true;}
			case 18: if (isValidDate(sNo.substr(6,4),sNo.substr(10,2),sNo.substr(12,2))) {return true;}
			}
		return false;
	},
	isInteger:function(v){
		var re = /^[0-9]+.?[0-9]*$/;
		return re.test(v);
	},
	/*
	用途：检查输入字符串是否只由汉字、字母、/组成
	输入：value：字符串
	返回：如果通过验证返回true,否则返回false
	*/
	isValidSpeciallyChar:function(string){
		
		var v=string;
		
		if(ValidValue(_PColl.ChinesePattern,v))
		{
			if(!ValidValue(_PColl.ChineseNamePattern,v))
			{
				return false;
			}		
		}
		else if(ValidValue(_PColl.rareChineseName1,v))
		{
			return true;
		}
		else if(ValidValue(_PColl.rareChineseName2,v))
		{
			return true;
		}
		else if(ValidValue(_PColl.rareChineseName3,v))
		{
			return false;
		}
		else if(ValidValue(_PColl.EnglishName,v))
		{
			return true;
		}
		else
		{
			return false;
		};
	
		return true;
	},
	/*判断是否有效的年月日*/
	isValidDateByYMD:function(iY, iM, iD) 
	{ 
		var undefined;								
		if ( iY != undefined && !isNaN(iY) && iY >=0 && iY<=9999 &&						
			iM != undefined && !isNaN(iM) && iM >=1   && iM<=12   &&					
			iD != undefined && !isNaN(iD) && iD >=1   && iD<=31  )  
		{					
			if (iY<50) 
				iY = 2000+iY; 
			else if (iY<100) 
				iY=1900+iY;						
			if (iM == 2  && (isLeapYear(iY)  && iD > 29 || !isLeapYear(iY) && iD>28) ||	
				iD == 31 && (iM<7 && iM%2==0 || iM>7 && iM%2==1) )							
				return false																
			else	
				return true      
		}														
		else  
			return false 
	},
	/*判断是否有效的日期*/
	isValidDate:function(d)
	{
		var str=d;d = d.replace(/\s+/g,""); 
		
		if(str.search(/^\d{4}-\d{1,2}-\d{1,2}$/) == 0){ 
			var y = parseInt(str.split("-")[0],10); 
			var m = parseInt(str.split("-")[1],10); 
			var d = parseInt(str.split("-")[2],10); 
			switch(m){ 
				case 1: 
				case 3: 
				case 5: 
				case 7: 
				case 8: 
				case 10: 
				case 12: 
				if(d>31){ 
					return false; 
				}else{ 
					return true; 
				} 
				break; 
				case 2: 
					if((y%4==0 && d>29) || ((y%4!=0 && d>28))){ 
						return false; 
					}else{ 
						return true; 
					} 
					break; 
				case 4: 
				case 6: 
				case 9: 
				case 11: 
					if(d>30){ 
						return false; 
					}else{ 
						return true; 
					} 
					break; 
				default: 
					return false; 
			} 
		}else{ 
			return false; 
		} 
			
	},
	isNumber:function(str){ 
		if(""==str){ 
			return false; 
		} 
			var reg = /\D/; 
			return str.match(reg)==null; 
	}

};

function $validator(t, vv){
	var v = vv.trim();
	switch(t){
		case "Cchar":{return c_validator.isValidSpeciallyChar(v);break;}
		case "passengerno":{return c_validator.isValidChinaIDCard(v);break;}
		case "empty":{return c_validator.isEmpty(v);break;}
		case "Cmobile":{return c_validator.isValidMobile(v);break;}
		case "Ctel":{return c_validator.isInteger(v);break;}
		case "email":{return c_validator.isValidEmail(v);break;}
		case "receiver":{return c_validator.isValidSpeciallyChar(v);break;}
		case "prov":{return c_validator.isEmpty(v);break;}
		case "city":{return c_validator.isEmpty(v);break;}
		case "address":{return c_validator.isEmpty(v);break;}
		case "ticketaddr":{return c_validator.isEmpty(v);break;}
		case "sendday":{return c_validator.isValidDate(v);break;}
		case "userid":{return c_validator.isEmpty(v)?!c_validator.isIllegalChar(v):false;break;}
		case "pwd":{return c_validator.isEmpty(v);break;}
		case "cpwd":{return c_validator.isEmpty(v);break;}
		case "zipcode":{return c_validator.isValidZipCode(v);break;}
		case "number":{return c_validator.isNumber(v);break;}
	}
}

function isLeapYear(y)
{
y=parseInt(y);
return (0==y%4&&((y%100!=0)||(y%400==0)));
}

/*判断是否有效的年月日*/
function isValidDate(iY, iM, iD) 
{ 
iY=parseInt(iY);
iM=parseInt(iM);
iD=parseInt(iD);

    var undefined									
    if ( iY != undefined && !isNaN(iY) && iY >=0 && iY<=9999 &&						
        iM != undefined && !isNaN(iM) && iM >=1   && iM<=12   &&					
        iD != undefined && !isNaN(iD) && iD >=1   && iD<=31  )  
    {					
        if (iY<50) 
            iY = 2000+iY; 
        else if (iY<100) 
            iY=1900+iY;						
        if (iM == 2  && (isLeapYear(iY)  && iD > 29 || !isLeapYear(iY) && iD>28) ||	
            iD == 31 && (iM<7 && iM%2==0 || iM>7 && iM%2==1) )							
	        return false																
        else	
            return true      
    }														
    else  
        return false 
}


function displayErrorMsg(e)
{
 var tmp="<hr>";
 for(x in e)
 {
  tmp+=""+x+"=>"+e[x]+"<br/>\n";
 }
 return tmp;
}

function getcheckcode(obj){
    obj.src="/ValidateCode.aspx?rng="+Math.random();
}

function setCookie(name, value, expires, path, domain){	var str = name + "=" + value + ";";	if (expires) str += "expires=" + expires + ";";	str += "path=" + (path ? path : "/") + ";";	if (domain) str += "domain=" + domain + ";";	document.cookie = str;}function getCookie(name){	var str = document.cookie;	var cookies = str.split("; ");	for (var i=0; i<cookies.length; i++)	{		if(cookies[i].split('=')[0]==name)		{			return cookies[i].split('=')[1];		}	}	return "";}


if (!window.createPopup) {   
    var __createPopup = function() {   
        var SetElementStyles = function( element, styleDict ) {   
            var style = element.style ;   
            for ( var styleName in styleDict )style[ styleName ] = styleDict[ styleName ] ;    
        }   
        var eDiv = document.createElement( 'div' );    
        SetElementStyles( eDiv, { 'position': 'absolute', 'top': 0 + 'px', 'left': 0 + 'px', 'width': 0 + 'px', 'height': 0 + 'px', 'zIndex': 1000, 'display' : 'none', 'overflow' : 'hidden' } ) ;   
        eDiv.body = eDiv ;   
        var opened = false ;   
        var setOpened = function( b ) {   
            opened = b;    
        }   
        var getOpened = function() {   
            return opened ;    
        }   
        var getCoordinates = function( oElement ) {   
            var coordinates = {x:0,y:0} ;    
            while( oElement ) {   
                coordinates.x += oElement.offsetLeft ;   
                coordinates.y += oElement.offsetTop ;   
                oElement = oElement.offsetParent ;   
            }   
            return coordinates ;   
        }   
        return {htmlTxt : '', document : eDiv, isOpen : getOpened(), isShow : false, hide : function() { SetElementStyles( eDiv, { 'top': 0 + 'px', 'left': 0 + 'px', 'width': 0 + 'px', 'height': 0 + 'px', 'display' : 'none' } ) ; eDiv.innerHTML = '' ; this.isShow = false ; }, show : function( iX, iY, iWidth, iHeight, oElement ) { if (!getOpened()) { document.body.appendChild( eDiv ) ; setOpened( true ) ; } ; this.htmlTxt = eDiv.innerHTML ; if (this.isShow) { this.hide() ; } ; eDiv.innerHTML = this.htmlTxt ; var coordinates = getCoordinates ( oElement ) ; eDiv.style.top = ( iX + coordinates.x ) + 'px' ; eDiv.style.left = ( iY + coordinates.y ) + 'px' ; eDiv.style.width = iWidth + 'px' ; eDiv.style.height = iHeight + 'px' ; eDiv.style.display = 'block' ; this.isShow = true ; } }   
    }   
    window.createPopup = function() {   
        return __createPopup();    
    }   
}  


function Go(position)
{
    if(position=="bottom")
    {
        document.documentElement.scrollTop=document.body.clientHeight;
        document.body.scrollTop=document.body.clientHeight;
    }
    if(position=="top")
    {
        document.documentElement.scrollTop=0;
        document.body.scrollTop=0;
    }
}

function fmoney(s, n)   
{   
   n = n > 0 && n <= 20 ? n : 2;   
   s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";   
   var l = s.split(".")[0].split("").reverse(),   
   r = s.split(".")[1];   
   t = "";   
   for(i = 0; i < l.length; i ++ )   
   {   
      t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");   
   }   
   return t.split("").reverse().join("") + "." + r;   
}   
function rmoney(s)   
{   
   return parseFloat(s.replace(/[^\d\.-]/g, ""));   
} 
function AddFavorite(sURL, sTitle) {
    try {
        window.external.addFavorite(sURL, sTitle);
    } catch(e) {
        try {
            window.sidebar.addPanel(sTitle, sURL, "");
        } catch(e) {
            alert("对不起,您的浏览器无法使用此功能，请使用Ctrl+D进行添加。");
        }
    }
}



function reinitIframe(){
var iframe = document.getElementById("huochepiao");
try{
if(iframe!=null){
   iframe.height = "2400px"; 
}
}catch (ex){}
}
window.setTimeout("reinitIframe()", 200);
